﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Entidades.Karaoke;

namespace Datos.Karaoke
{
    public class KarCategoriaDAL
    {
        public static string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();

        public static List<KarCategoria> ListarCategoria()
        {
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("SELECT [iDCategoria], [categoria], [estado] FROM [Kar_Categoria] ", con);
            com.CommandType = System.Data.CommandType.Text;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List<KarCategoria> lista = new List<KarCategoria>();
                KarCategoria obj = null;
                while (dr.Read())
                {
                    obj = new KarCategoria();

                    obj.iDCategoria = Convert.ToInt32(dr["iDCategoria"].ToString());
                    obj.categoria = Convert.ToString(dr["categoria"].ToString());
                    obj.Estado = (Convert.ToBoolean(dr["Estado"]) ? 1 : 0);
                    obj.strEstado = (obj.Estado == 0 ? "Activo" : "Inactivo");

                    lista.Add(obj);
                }
                dr.Close();

                return lista;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }

        public static List<KarCategoria> ListarCategoriaActCancion()
        {
            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("select '0' iDCategoria,'Seleccione Item' categoria FROM Kar_Idioma UNION SELECT [iDCategoria], [categoria] FROM [Kar_Categoria] ", con);
            com.CommandType = System.Data.CommandType.Text;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List<KarCategoria> lista = new List<KarCategoria>();
                KarCategoria obj = null;
                while (dr.Read())
                {
                    obj = new KarCategoria();

                    obj.iDCategoria = Convert.ToInt32(dr["iDCategoria"].ToString());
                    obj.categoria = Convert.ToString(dr["categoria"].ToString());

                    lista.Add(obj);
                }
                dr.Close();

                return lista;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
